package Lab;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * description:
 * author:zcx
 * lenovo
 * 时间：2022.01.29.17.45
 */
public class LamStringDemo {
    public static void main(String[] args) {
        var list=new ArrayList<String>(List.of("java","c","sdsdsd","vb","javascript","jsp","phtyon"));
        //list.add(List.of("java","c","sdsdsd","vb","javascript","jsp"));
        //根据字符串升序
        Collections.sort(list,(a,b)->a.length()-b.length());
        Collections.sort(list, Comparator.comparingInt(String::length));
        //根据字符串升序
        Collections.sort(list,(a,b)->b.length()-a.length());
        System.out.println(list);

        //根据字符串乱序
        //Collections.shuffle(list);
        Collections.sort(list,(a,b)->Math.random()>.5?-1:1);
        System.out.println(list);

    }

    public static void sort(String[] args) {
        var list=new ArrayList<String>(List.of("java","c","sdsdsd","vb","javascript","jsp","phtyon"));
        //list.add(List.of("java","c","sdsdsd","vb","javascript","jsp"));
        System.out.println(list);
        //升序
        Collections.sort(list);
        Collections.sort(list,(a,b)->a.compareTo(b));
        Collections.sort(list,String::compareTo);
        System.out.println(list);
        //降序
        Collections.sort(list,(a,b)->b.compareTo(a));
        Collections.sort(list,Collections.reverseOrder());
        System.out.println(list);
        //乱序
        Collections.shuffle(list);
        System.out.println(list);

    }
}
